<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }

    div {
      background: green;
      border: 2px solid red;
      width: 300px;
      height: 200px;
      margin: 20px auto;
    }
  </style>
</head>

<body>
  <div></div>
  <script>
    let div = document.querySelector("div");
    window.addEventListener("resize", function () {
      console.log(window.innerWidth); //获取屏幕的宽度
      console.log(window.innerHeight); //获取屏幕的高度
      if (window.innerWidth <= 800) {
        div.style.display = "none";
      } else {
        div.style.display = "block";
      };
    });
  </script>
</body>

</html>